using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using net_work.Data.Entity.Sys;

namespace net_work.Config.DataBaseConfig.Sys;

/// <summary>
/// 部门实体配置类
/// </summary>
public class DepartmentEntityTypeConfiguration : IEntityTypeConfiguration<Department>
{
    public void Configure(EntityTypeBuilder<Department> builder)
    {
        builder.ToTable("sys_dep");

        builder.HasKey(d => d.Id);

        builder.HasIndex(d => d.DepName).IsUnique();

        // 配置字段名映射
        builder.Property(d => d.Id).HasColumnName("dep_id");
        builder.Property(d => d.DepName).HasColumnName("dep_name").IsRequired().HasMaxLength(64);
        builder.Property(d => d.DepPhone).HasColumnName("dep_phone").HasMaxLength(15);
        builder.Property(d => d.DepAddr).HasColumnName("dep_addr").HasMaxLength(256);
        builder.Property(d => d.DepEmail).HasColumnName("dep_email").HasMaxLength(128);
        builder.Property(d => d.HeadTeacherId).HasColumnName("head_tcr_id");
        builder.Property(d => d.CollegeId).HasColumnName("colle_id").IsRequired();

        builder.Property(d => d.CreatedBy).HasColumnName("create_by").IsRequired().HasMaxLength(64);
        builder.Property(d => d.CreatedTime).HasColumnName("create_time").IsRequired();
        builder.Property(d => d.UpdatedBy).HasColumnName("update_by").IsRequired().HasMaxLength(64);
        builder.Property(d => d.UpdatedTime).HasColumnName("update_time").IsRequired();
        builder.Property(d => d.Remark).HasColumnName("remark").HasMaxLength(256);
        builder.Property(d => d.DelFlag).HasColumnName("del_flag").HasDefaultValue('0');
    }
}